package com.wuzf.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.GeneratedKeyHolder;

import com.wuzf.dao.PermissionDao;
import com.wuzf.entity.Permission;
import com.wuzf.utils.JdbcTemplateUtils;

public class PermissionDaoImpl implements PermissionDao {
	
	private JdbcTemplate template = JdbcTemplateUtils.JdbcTemplate();

	//生成权限数据
	public Permission createPermission(final Permission permission) {
		final String sql = "insert into sys_permissions (permission, description, available) values (?, ?, ?) ";
		GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
		template.update(new PreparedStatementCreator() {
			public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
				PreparedStatement psm = con.prepareStatement(sql, new String[]{"id"});
				psm.setString(1, permission.getPermission());
				psm.setString(2, permission.getDescription());
				psm.setBoolean(3, permission.getAvailable());
				return psm;
			}
		}, keyHolder);
		permission.setId(keyHolder.getKey().longValue());
		return permission;
	}		

	public void deletePermission(Long permissionId) {
		// TODO Auto-generated method stub

	}

}
